﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL;

namespace PeisongWeb.admin
{
    public partial class systemUpgradeEdit : adminPage
    {
        protected int id
        {
            get
            {
                int tmp;
                try { tmp = Convert.ToInt32(ViewState["id"]); }
                catch { tmp = 0; }
                return tmp;
            }
            set
            { ViewState["id"] = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("AF", 1))
                {
                    if (Request.QueryString["category"] != null)
                    {
                        if (Library.Number.IsIntPositive(Request.QueryString["category"]))
                        {
                            id = Convert.ToInt32(Request.QueryString["category"]);
                        }
                    }
                    if (id != 0)
                    {

                        getDetails();
                    }
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        private void getDetails()
        {
            SysUpgradeEntity entity = logic.sysUpgrade.getById(id);
            txt_Name.Text = entity.Title;
            txtDesc.Text = entity.Description;
            txtStartDt.SelectedDate = entity.StartDt;
            txtEndDt.SelectedDate = entity.EndDt;
            chx_isShow.Checked = entity.IsShow;
        }
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            SysUpgradeEntity entity = new SysUpgradeEntity();
            entity.Title = txt_Name.Text;
            entity.Description = txtDesc.Text;
            entity.StartDt = txtStartDt.SelectedDate;
            entity.EndDt = txtEndDt.SelectedDate;
            entity.IsShow = chx_isShow.Checked;
            entity.AdminId = logic.sysAdmin.AdminID;

            if (id != 0)
            {
                entity.Suid = id;
                logic.sysUpgrade.update(entity);
            }
            else
            {
                logic.sysUpgrade.insert(entity);

            }

            Library.Script.ClientMsgUrl("保存成功！", "systemUpgradeList.aspx");

        }
    }
}
